<?php
/*
 * Hooligan - A sports facilities management software
 * Copyright (C) 2009/2010 Gianluca Bargelli <g.bargelli@gmail.com>,
 * Andrea Biocco <abiocco@gmail.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Project home: <http://code.google.com/hooligan>
 *
*/
require_once('../Controller/Common/Controller_Common_Config.php');
require_once ('../Template/Template_Admin.php');
/**
 * Description of Controller_Impianti
 *
 * @author andrea
 */
class Controller_Gestore_AddGestore {

    public static function newGestoreForm () {
        if (!array_key_exists('nome',$_POST)) {
            echo("<form action='addGestore.php' method='post'>");
            echo("<table>");
            echo("<tr>");
            echo("<th colspan='2'>Generalità</th>");
            echo("</tr>");
            echo("<tr>");
            echo("<th colspan='2' class='titoletto'>Utente</th>");
            echo("<tr>");
            echo("<td>Password:</td>");
            echo("<td><input type='password' name='pwd'></td>");
            echo("</tr>");
            echo("<tr>");
            echo("<td>Controllo password:</td>");
            echo("<td><input type='password' name='pwd2'></td>");
            echo("</tr>");
            echo("<tr>");
            echo("<th colspan='2' class='titoletto'>Gestore</th>");
            echo("</tr>");
            echo("<tr>");
            echo("<td>Nome:</td>");
            echo("<td><input type='text' name='nome'></td>");
            echo("</tr>");
            echo("<tr>");
            echo("<td>Cognome:</td>");
            echo("<td><input type='text' name='cognome'></td>");
            echo("</tr>");
            echo("<tr>");
            echo("<td>E-Mail:</td>");
            echo("<td><input type='text' name='email'></td>");
            echo("</tr>");
            echo("<tr>");
            echo("<td>Data di nascita:</td>");
            echo("<td><input type='text' size='2' maxlength='2' value='gg' name='nascita_giorno'> <input type='text' size='2' maxlength='2' value='mm' name='nascita_mese'> <input type='text' size='4' maxlength='4' value='yyyy' name='nascita_anno'></td>");
            echo("</tr>");
            echo("<tr>");
            echo("<td>Tel:</td>");
            echo("<td><input type='text' name='tel'></td>");
            echo("</tr>");
            echo("<tr>");
            echo("</table>");
            echo("<input type='submit' value='Crea!'>");
            echo("</form>");
        }else {
            Controller_Gestore_AddGestore::newGestore(strtolower($_POST['nome'].".".$_POST['cognome']),$_POST['pwd'],$_POST['email'],$_POST['nome'], $_POST['cognome'], $_POST['nascita_anno']."-".$_POST['nascita_mese']."-".$_POST['nascita_giorno'], $_POST['tel']);
            header("location:adminUtente.php?filter=gestori");
        }
    }
    public static  function newGestore ($user,$pwd,$email,$nome,$cognome,$nascita,$tel) {
        $amministratore= "gianluca.bargelli";
        $sql = "INSERT INTO PrenoTest.Utente (username,pwd)
                VALUES ('".$user."', SHA1('".$pwd."'))";
        $sql2 = "INSERT INTO PrenoTest.Gestore (Utente_username,email_cus, nome,
                cognome, data_n, tel)
                VALUES ('".$user."','".$email."','".$nome."','".$cognome."','".$nascita."','".$tel."')";
        $connection=new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
        $db = new Model_Db($connection);
        $db->eseguiQuery($sql);
        $db->eseguiQuery($sql2);
    }
}
?>
